package com.gitee.feizns.quickstart.ql.express;

import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import com.ql.util.express.IExpressContext;
import lombok.SneakyThrows;

import java.util.Map;

/**
 * ql express
 * @author feizns
 * @since 2025/04/13
 */
public class QlExpress {

    /**
     * 跑步者
     */
    public static final ExpressRunner runner = new ExpressRunner();

    /**
     * 执行
     * @param expressionString 表达式字符串
     * @return {@link Object }
     */
    @SneakyThrows
    public static Object execute(String expressionString) {
        return runner.execute(expressionString, null, null, false, false);
    }

    /**
     * 执行
     * @param expressionString 表达式字符串
     * @return {@link Object }
     */
    @SneakyThrows
    public static Object execute(String expressionString, IExpressContext<String, Object> context) {
        return runner.execute(expressionString, context, null, false, false);
    }

    /**
     * 执行
     * @param expressionString 表达式字符串
     * @return {@link Object }
     */
    @SneakyThrows
    public static Object execute(String expressionString, Map<String, Object> context) {
        return runner.execute(expressionString, context(context), null, false, false);
    }

    /**
     * 上下文
     * @param mapContext {@link Map}
     * @return {@link DefaultContext }<{@link String }, {@link Object }>
     */
    public static DefaultContext<String, Object> context(Map<String, Object> mapContext) {
        DefaultContext<String, Object> defaultContext = new DefaultContext<>();
        defaultContext.putAll(mapContext);
        return defaultContext;
    }

}
